<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>TinyMce富文本编辑器</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./tinymce/tinymce.min.js"></script>
    <script type="text/javascript" src="./elfinder/js/jquery-1.11.1.js"></script>
    <script src="./common/utils.js"></script>
    <script>
        window._editor = tinyMCE.init({
            selector: 'textarea#full-featured',
            plugins: 'code print preview importcss searchreplace autolink autosave save directionality visualblocks visualchars fullscreen filemanager image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists wordcount imagetools textpattern noneditable help charmap emoticons searchreplace',
            language:'zh_CN',
            //skin: "oxide-dark",
            mobile: {
                plugins: 'print preview importcss searchreplace autolink autosave save directionality visualblocks visualchars fullscreen filemanager image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists wordcount textpattern noneditable help charmap quickbars emoticons searchreplace'
            },
            menu: {
                tc: {
                    title: 'TinyComments',
                    items: 'addcomment showcomments deleteallconversations'
                }
            },
            menubar: 'file edit view insert format tools table tc help',
            toolbar: 'code |undo redo | bold italic underline strikethrough | alignleft aligncenter alignright | outdent indent | numlist bullist forecolor backcolor removeformat charmap emoticons filemanager image media pageembed link anchor || codesample searchreplace preview print save fullscreen',
            autosave_ask_before_unload: true,
            autosave_interval: "30s",
            autosave_prefix: "{path}{query}-{id}-",
            autosave_restore_when_empty: false,
            autosave_retention: "2m",
            convert_urls: false,
            extended_valid_elements: 'span',
            image_advtab: true,
            image_class_list: [
                { title: 'None', value: '' },
                { title: 'Some class', value: 'class-name' }
            ],
            importcss_append: true,
            templates: [
                { title: 'New Table', description: 'creates a new table', content: '<div class="mceTmpl"><table width="98%%"  border="0" cellspacing="0" cellpadding="0"><tr><th scope="col"> </th><th scope="col"> </th></tr><tr><td> </td><td> </td></tr></table></div>' },
            ],
            template_cdate_format: '[Date Created (CDATE): %m/%d/%Y : %H:%M:%S]',
            template_mdate_format: '[Date Modified (MDATE): %m/%d/%Y : %H:%M:%S]',
            height: window.innerHeight,
            image_caption: true,
            quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote filemanager quicktable',
            noneditable_noneditable_class: "mceNonEditable",
            toolbar_mode: 'inline',
            spellchecker_dialog: true,
            spellchecker_whitelist: ['Ephox', 'Moxiecode'],
            content_style: ".mymention{ color: gray; }",
            contextmenu: "link bold copy filemanager image",
            a11y_advanced_options: true,
            draggable_modal: true,
            branding: false,
            forced_root_block : "",
            save_enablewhendirty: true,
            save_onsavecallback: function () {
                var file = queryUrlParam("file");
                if(file){
                    $.ajax({
                        type:"PUT",
                        url:"./elfinder/connector",
                        data:{cmd:'put',target:file,encoding:'UTF-8',content:this.getContent()},
                        success:function(res) {
                            Swal.fire('保存',"保存成功","success");
                        },
                        error:function (err) {
                            console.error(err);
                            Swal.fire('保存',"保存失败","error");
                        }
                    });
                }
            }
        });
    </script>
    <style>
        body {
            padding: 0;
            margin: 0;
        }
    </style>
</head>
<body>
<textarea id="full-featured"></textarea>
<script type="text/javascript">
    (function () {
        var file = queryUrlParam("file");
        if(file){
            $.ajax({
                type:"GET",
                url:"./elfinder/connector",
                data:{cmd:'get',target:file,conv:0},
                success:function (res) {
                    tinyMCE.editors[0].setContent(res.content);
                },
                error:function (err) {
                    console.error(err);
                }
            });
        }
    })();
</script>
<script src="./common/sweetalert2@9.js"></script>
</body>
</html>